<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:action="http://www.w3.org/1999/xhtml">
<head>


	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>首页</title>
	<link rel="stylesheet" href="../static/css/main.css" type="text/css" />

<meta charset="UTF-8">


<title>书城首页</title>
	<link type="text/css" rel="stylesheet" href="../static/css/style.css" >
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script>

		$(function () {



			$(".add_cart_btn").click(function () {
				let addCartId=$(this).attr("addCartId");
				let userName=$(".um_span").text();
				$.ajax({
							url:"orders/addCart",
							type:"get",
							data:{
								"bookId":addCartId,
								"userName":userName
							},
							success:function (data) {
								console.log(data)
								if (!data.flag){
									location.href="/login.html"
								}
								else {
									$("#addMsg").text(data.msg)
									$("#add_cart_msg").css("display","block")
								}
							}

						}

				)
			})



		})



	</script>
</head>

<body class="main">

<div id="divhead">
	<table cellspacing="0" class="headtable">
		<tr>
			<td>
				<a href="#">
					<img src="../static/images/logo.png" width="200" height="60" border="0" />
				</a>
			</td>


			<td style="text-align:right">
				<th:block th:if="${session.user!=null}">
					<img src="../static/images/cart.gif" width="26" height="23" style="margin-bottom:-4px" />&nbsp;
					<a th:href="'/book/cart?username='+${session.user.username}" >购物车</a>
				</th:block>
					 <a href="#">帮助中心</a>
				| <a href="#">我的帐户</a>

				<th:block th:if="${session.user==null}">
					| <a th:href="@{/book/login}">登录</a>
					| <a th:href="@{/book/register}">注册</a>
				</th:block>
				<th:block th:if="${session.user!=null}">
					<span>欢迎<span class="um_span" th:text="${session.user.username}"></span>光临书城</span>
					| <a th:href="'order?username='+${session.user.username}"+>我的订单</a>
					| <a th:href="'loginClose?username='+${session.user.username}">注销</a>&nbsp;&nbsp;
				</th:block>
			</td>





		</tr>
	</table>
</div>

<div id="divmenu">
	<a href="index?category=文学">文学</a>
	<a href="index?category=生活">生活</a>
	<a href="index?category=计算机">计算机</a>
	<a href="index?category=外语">外语</a>
	<a href="index?category=经管">经管</a>
	<a href="index?category=励志">励志</a>
	<a href="index?category=社科">社科</a>
	<a href="index?category=学术">学术</a>
	<a href="index?category=少儿">少儿</a>
	<a href="index?category=艺术">艺术</a>
	<a href="index?category=原版">原版</a>
	<a href="index?category=科技">科技</a>
	<a href="index?category=考试">考试</a>
	<a href="index?category=生活百科">生活百科</a>
	<a href="index?category=" style="color:#FFFF00">全部商品目录</a>
</div>

<div id="divsearch">
	<form action="#" id="searchform">
		<table width="100%" border="0" cellspacing="0">
			<tr>
				<td style="text-align:right; padding-right:220px">
					Search
					<input type="text" name="textfield" class="inputtable" id="textfield" value="请输入书名"
						   onmouseover="this.focus();"
						   onclick="my_click(this, 'textfield');"
						   onBlur="my_blur(this, 'textfield');"/>
					<a href="#">
						<img src="../static/images/serchbutton.gif" border="0" style="margin-bottom:-4px" onclick="search()"/>
					</a>
				</td>
			</tr>
		</table>
	</form>
</div>

	<div id="main">


		<div id="book">
			<div class="book_cond">
				<form th:action="@{/queryBooks}" method="get">
					价格：<input id="min" type="text" name="min" value=""> 元 -
						<input id="max" type="text" name="max" value=""> 元
						<input type="submit" value="查询" />
				</form>
			</div>
			<div style="text-align: center">
				<span > &nbsp;</span>
					<span th:text="${error}" id="error" style="color: red" > &nbsp;</span>
				<div style="display: none" id="add_cart_msg">
					您刚刚将<span style="color: red" id="addMsg">时间简史</span>加入到了购物车中
				</div>
			</div>
			<div class="b_list" th:each="book:${pageInfo.list}" >
				<div class="img_div">
					<img class="book_img" alt="" th:src="${book.imgurl}" />
				</div>
				<div class="book_info">
					<div class="book_name">
						<span class="sp1">书名:</span>
						<span class="sp2" th:text="${book.name}"></span>
					</div>

					<div class="book_price">
						<span class="sp1">价格:</span>
						<span class="sp2" th:text="${book.price}">￥30.00</span>
					</div>
					<div class="book_sales">
						<span class="sp1">分类:</span>
						<span class="sp2" th:text="${book.category}">230</span>
					</div>
					<div class="book_amount">
						<span class="sp1">库存:</span>
						<span class="sp2" th:text="${book.pnum}">1000</span>
					</div>
					<div class="book_add">
						<button th:addCartId="${book.id}" class="add_cart_btn">加入购物车</button>
					</div>


				</div>
			</div>


		</div>

		<div id="page_nav">
			<th:block th:if="${pageInfo.hasPreviousPage}">
				<a th:href="@{/book/index(pageNum=1)}">首页</a>
				<a th:href="@{/book/index(pageNum=${pageInfo.pageNum}-1)}">上一页</a>
			</th:block>
							<th:block th:each="pageNum:${pageInfo.navigatepageNums}">
								<th:block th:if="${pageNum==pageInfo.pageNum}">
									【<span th:href="@{/book/index(pageNum=${pageNum})}" th:text="${pageNum}" ></span>】
								</th:block>
								<th:block th:if="${pageNum!=pageInfo.pageNum}">
									<a th:href="@{/book/index(pageNum=${pageNum})}" th:text="${pageNum}" ></a>
								</th:block>

							</th:block>
			<th:block th:if="${pageInfo.hasNextPage}">
				<a th:href="@{/book/index(pageNum=${pageInfo.pageNum}+1)}">下一页</a></li>
				<a th:href="@{/book/index(pageNum=${pageInfo.pages})}">末页</a>
			</th:block>

		共<th:block th:text="${pageInfo.pages}"></th:block></span>页，<th:block th:text="${pageInfo.total}"></th:block></span>条记录 到第<input th:value="${pageInfo.getPageNum()}" name="pn" id="pn_input"/>页
		<input type="button" value="确定" id="submit">
			<script>
				$("#submit").click(function () {
					let pageNum= $("#pn_input").val();
					location.href="/book/index?pageNum="+pageNum;
				})
			</script>
		</div>

	</div>



<div id="divfoot">
	<table width="100%" border="0" cellspacing="0" >
		<tr>
			<td rowspan="2" style="width:10%">
				<img src="../static/images/logo.png" width="195" height="50"
					 style="margin-left:175px" />
			</td>
			<td style="padding-top:5px; padding-left:50px">
				<a href="#">
					<font color="#747556"><b>CONTACT US</b></font>
				</a>
			</td>
		</tr>
		<tr>
			<td style="padding-left:50px">
				<font color="#CCCCCC">
					<b>COPYRIGHT 2015 &copy; BookStore All Rights RESERVED.</b>
				</font>
			</td>
		</tr>
	</table>
</div>
<!-- 网上书城底部  end -->


</body>
</html>
